//
//  MemoryStream.m
//  Protocol
//
//  Created by  user on 11-1-9.
//  Copyright 2011 GuangZhouXuanWu. All rights reserved.
//

#import "MemoryStream.h"

@implementation CMemoryStream

-(id)init
{
    self = [super init];
	_position=0;
    _data = [NSMutableData new];
	return self;
}

@synthesize data = _data;
@synthesize position = _position;

-(NSUInteger)length
{
    return [_data length];
}

- (void)appendBytes:(const void *)bytes length:(NSUInteger)length
{
    [_data appendBytes:bytes length:length];
}

- (void)appendData:(NSData *)other
{
    [_data appendData:other];
}

- (void)increaseLengthBy:(NSUInteger)extraLength
{
    [_data increaseLengthBy:extraLength];
}

- (void)replaceBytesInRange:(NSRange)range withBytes:(const void *)bytes
{
    [_data replaceBytesInRange:range withBytes:bytes];
}

- (void)resetBytesInRange:(NSRange)range
{
    [_data resetBytesInRange:range];
}

- (void)replaceBytesInRange:(NSRange)range withBytes:(const void *)replacementBytes length:(NSUInteger)replacementLength
{
    [_data replaceBytesInRange:range withBytes:replacementBytes length:replacementLength];
}

- (NSData *)subdataWithRange:(NSRange)range
{
    return [_data subdataWithRange:range];
}

- (void)getBytes:(void *)buffer length:(NSUInteger)length
{
    [_data getBytes:buffer length:length];
}

- (void)getBytes:(void *)buffer range:(NSRange)range
{
    [_data getBytes:buffer range:range];
}

- (BOOL)isEqualToData:(CMemoryStream *)other
{
    return [_data isEqualToData:other.data];
}

-(BOOL)isEndPosition
{
	return _position==self.length?YES:NO;
}

- (NSString *)description
{
    return [_data description];
}

-(void)dealloc
{
    [_data release_mm];
	superdealloc_mm;
}

@end
